<template>

    <el-dialog title="新增部门" :visible="departmentAddShow" @close="dialogClose" width="40%">

        <el-form :model="ruleForm" :rules="rules" ref="departmentAdd" label-width="auto" class="demo-ruleForm">
            <el-form-item label="部门名称" prop="name">
                <el-input type="text" v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="管理者ID" prop="glzid">
                <el-input v-model="ruleForm.glzid"></el-input>
            </el-form-item>
            <el-form-item label="管理者姓名" prop="glzxm">
                <el-input type="text" v-model="ruleForm.glzxm"></el-input>
            </el-form-item>
            <el-form-item label="部门人数" prop="bmrs">
                <el-input type="text" v-model="ruleForm.bmrs"></el-input>
            </el-form-item>
            <el-form-item label="隶属企业ID" prop="qyid">
                <el-input v-model="ruleForm.qyid"></el-input>
            </el-form-item>
            <el-form-item label="隶属企业名称" prop="qymc">
                <el-input v-model="ruleForm.qymc"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input type="textarea" v-model="ruleForm.remark">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
                </el-button>
                <el-button @click="dialogClose" class="pull-right">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

</template>
<script>
import { addDepartment } from '@/api/systemAdministrator/departmentManage';
export default {
    name: 'departmentAdd',
    data () {
        return {
            ruleForm: {},
            rules: {
                name: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                glzid: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                glzxm: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                bmrs: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                qyid: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                qymc: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ]
            }
        };

    },

    props: {
        departmentAddShow: {
            type: Boolean
        }
    },
    methods: {

        submitForm () {
            if (this.ruleForm.remark == null) {
                this.ruleForm.remark = '-'
            }
            this.$refs.departmentAdd.validate((valid) => {
                if (valid) {
                    addDepartment(this.ruleForm).then((res) => {
                        if (res) {
                            this.$message.success('操作成功！')
                            this.$emit('dialogClose');
                            this.$emit('getList')
                        }
                    })
                }
                else {
                    return;
                }
            });
        },
        dialogClose () {
            this.$emit('dialogClose');
        }
    },



}
</script>
<style lang="less" scoped>
.select {
    width: 100%;
}
</style>